package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.product.client.ProductFeignClient;
import com.atguigu.gmall.product.model.SkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * title:
 * author: Gyh
 * date:2023-05-05 18:34
 * Description:
 */
@Controller
public class CartController {

    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * 渲染商品加购成功页面
     * @param model
     * @param skuId
     * @param skuNum
     * @return
     */
    @GetMapping("/addCart.html")
    public String addCartHtml(Model model,
                              @RequestParam("skuId") Long skuId,
                              @RequestParam("skuNum") Integer skuNum){
        //远程调用商品微服务获取商品信息
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
        model.addAttribute("skuInfo",skuInfo);
        model.addAttribute("skuNum",skuNum);
        //跳转商品加购成功页面
        return "/cart/addCart";
    }

    /**
     * 渲染购物车列表页面
     * @return
     */
    @GetMapping("/cart.html")
    public String cartListHtml(){
        return "/cart/index.html";
    }
}
